var globalDatagrid = new Array();
var googleUserMap;
var googleFriendMap;
var googleWorldMap;

/*	WS needed
	getUserComment(userId) return TabCommentaire
	getUserAccount(userId) return User
	getUserFriend(userId) return TabUser
	getLastComment(nbComment) return TabCommentaire
	
	setNewName(User) return true or false;
	setNewPassword(User) return true or false;
	setNewMail(User) return true or false;
*/

function getTabMyComment()
{
	console.log('getTabMyComment()');
	var comments =  WSGetComment('moi');
	var name =  'userComment';
	var paramNames = ['Comment','Date','Actions'];
	var parameters = WSGetComment('moi');/*cookies user*/		
	
	for( var i in comments )
	{
		parameters[i][0] = comments[i][1].substr(0,25)+'...';
		parameters[i][1] = comments[i][2];
		var deleteButton = '<input id=\'buttonDelete\' type=\'button\' onClick="WSDeleteComment(\''+comments[i][0]+'\')" ></input>';
		var seeButton = '<input id=\'buttonSee\' type=\'button\' onClick="setCenterToCommentUserMap('+comments[i][3]+','+comments[i][4]+')" ></input>';
		parameters[i][2] = seeButton+deleteButton;
	}
				
	thisDatagrid = new Datagrid(name,parameters,paramNames);
	globalDatagrid.push(thisDatagrid);
	thisDatagrid.buildTable();
	thisDatagrid.buildPager();
}

function getTabUserComment()
{
	console.log('getTabUserComment()');
	var name =  'userComment';
	var paramNames = ['Sender','Comment','Date','Actions'];
	var parameters = 	[	['me',"La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"11C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"11La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"11Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"22C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"22La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"22Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"22C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"33La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"33Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"33C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"44La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"44Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"44C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"55La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"55Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"55C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn'],
							['me',"66La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25','btn'],
							['truc',"66Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15','btn'],
							['azerrty',"66C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05','btn']
						];
			/*"<input type="button" onclick="rien" id="buttonSee">
		<input type="button" onclick="rien" id="buttonSee">"*/		
	
	for( var i in parameters )
	{
		parameters[i][1] = parameters[i][1].substr(0,20)+'...';
		parameters[i][3] = '<input id=\'buttonSee\' type=\'button\' ></input><input id=\'buttonDelete\' type=\'button\' ></input>';//getMessageInput();
	}
						
	thisDatagrid = new Datagrid(name,parameters,paramNames);
	globalDatagrid.push(thisDatagrid);
	thisDatagrid.buildTable();
	thisDatagrid.buildPager();
}

function getTabUserFriend()
{
	console.log('getTabUserFriend()');
	var name =  'userFriend';
	var paramNames = ['Pseudo','Comments','Actions'];
	var parameters = [	['Jeremy',3,'btn'],
						['Charles',3,'btn'],
						['André',7,'btn'],
						['Sandra',0,'btn'],
						['Helene',1,'btn'],
						['Adrien',3,'btn'],
						['Alexis',3,'btn'],
						['Charlotte',7,'btn'],
						['Alexandre',0,'btn'],
						['Benjamin',1,'btn'],
						['Carolanne',3,'btn'],
						['Sebastien',3,'btn'],
						['Perrine',7,'btn'],
						['Audrey',0,'btn'],
						['Aurélie',1,'btn'],
						['Corentin',3,'btn'],
						['oZ7EYIB',3,'btn'],
						['Af5kjh',7,'btn'],
						['Pj8dhf eioryu',0,'btn'],
						['Rd6gfg',1,'btn'],
						['xx8xxx',3,'btn'],
						['oZ6EYIB',3,'btn'],
						['Af8kjh',7,'btn'],
						['Pj6dhf eioryu',0,'btn'],
						['Rd9gfg',1,'btn'],
						['xx1xxx',3,'btn'],
						['oZ9EYIB',3,'btn'],
						['Af1kjh',7,'btn'],
						['Pj9dhf eioryu',0,'btn'],
						['Rd1gfg',1,'btn'],
						['xxx9xx',3,'btn'],
						['oZ30EYIB',3,'btn'],
						['Af0kjh',7,'btn'],
						['Pj3dhf eioryu',0,'btn'],
						['Rd0gfg',1,'btn'],
						['xxx3xx',3,'btn'],
						['oZE0YIB',3,'btn'],
						['Afk3jh',7,'btn'],
						['Pj22d0hf eioryu',0,'btn'],
						['Rd22g3fg',1,'btn'],
						['xxx223xx',3,'btn'],
						['oZE220YIB',3,'btn'],
						['1Afk223jh',7,'btn'],
						['1Pj22d0hf eioryu',0,'btn'],
						['1Rd22g3fg',1,'btn']
					];
	
	thisDatagrid = new Datagrid(name,parameters,paramNames);
	globalDatagrid.push(thisDatagrid);
	thisDatagrid.buildTable();
	thisDatagrid.buildPager();
}

function getWorldMap()
{
	console.log('getWorldMap()');
	var messages = 	[	[0,"La B.U est en rénovation jusqu'en 2016",50.609370,3.142110,'2013-09-27 14:18:25',,0,1],
						[1,"Ici c'est la salle des master 2 IAGL !",50.609772,3.136768,'2013-08-27 12:13:15',,1,1],
						[2,"C tro b1 la tour FL, g u tro peur lol!",48.858158,2.294660,'2013-09-10 09:55:05',,2,1],
						[1,"Visite de la statue de la liberté, c'est génial !",40.689254,-74.044596,'2013-07-20 12:13:15',,1,1],
						[2,"Ici on envois des fusées dans l'espace",5.239352,-52.768516,'2013-09-10 09:55:05',,2,1],
						[0,"Amphi Bacchus!",50.609579,3.136413,'2013-08-27 12:13:15',,1,1],
						[3,"KFC",50.612738,3.123405,'2013-09-10 09:55:05',,2,2],
						[1,"Ils ont tous les modéle de BMW.",35.661132,139.728688,'2013-08-27 12:13:15',,1,1],
						[2,"Il faut avoir des tympans en betons.",-26.234841,27.982729,'2013-09-10 09:55:05',,2,1],
						[4,"LEROY MERLIN, Super PROMO : pour 1000 clous achetés un marteau est offert.",50.613773,3.127281,'2013-08-27 12:13:15',,1,2]
						];
	
	//$(document.createElement('script')).attr("type","text/javascript").attr("src","http://maps.google.com/maps/api/js?sensor=false").prependTo($('body'));
	
	var worldMapBloc = $(document.createElement('div')).attr("id","worldMap").appendTo($('#bloc_page'));
	
	/* GOOGLE MAP */	
	var latlng = new google.maps.LatLng(50.60937,3.14211);
	/* HYBRID ROADMAP SATELLITE TERRAIN */
	var options = {
		center: latlng,
		zoom: 2,
		mapTypeId: google.maps.MapTypeId.HYBRID
	};
	 
	var carte = new google.maps.Map(document.getElementById("worldMap"), options);
	/* GOOGLE MAP FIN */
	
	/**************** AJOUT DE MARQUEUR ****************/

	//création de la liste de marqueurs
	var listeMarqueur = new Array();
	
	//création du marqueur
	for( var i in messages )
	{
		var marqueur = new google.maps.Marker({
			position: new google.maps.LatLng(messages[i][2],messages[i][3]),
			map: carte
		});
		marqueur.setTitle(messages[i][1]);
		if(messages[i][7]==2)
		marqueur.setIcon('images/marqueur_small.png');
		else
		marqueur.setIcon('images/marqueur_very_small.png');
		listeMarqueur.push(marqueur);
	}
	
	/** INFO WINDOW **/
	/* var infoWindow = new google.maps.InfoWindow({
		content  : '<b>'+messages[0]+' a dit :</b><br>'+messages[1]+'<br><i>'+messages[4]+'</i>',
		position : latlng
	}); */
	
	/********************* FIN ***********************/
	
	
	/**************** GESTION DU CLICK SUR LE MARQUEUR ****************/
	for( var i in listeMarqueur )
	{
		//google.maps.event.addListener(listeMarqueur[i], 'click', function() {
		listeMarqueur[i].click = function(){	
			//document.getElementById("test")
			//document.getElementById('set_message').innerHTML="<p>La B.U est en rénovation jusqu'en 2016. C'est trés long tout ça !</p>";//messages[1];
			//var boxText = document.getElementById("message");//document.createElement("div");
			/*boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
			boxText.innerHTML = "City Hall, Sechelt<br>British Columbia<br>Canada";*/
			
			carte.setZoom(16);
			carte.setCenter(marker.getPosition());
			
			/** PERSONNALISATION DE LA FENETRE **/
			 var myOptions = {
				 content: "<br><p style='padding:5px;color:#000' >"+messages[i][1]+"</p><br><br><br><br><br><br><br><br><br>"
				,disableAutoPan: false
				,maxWidth: 0
				,pixelOffset: new google.maps.Size(-75, -150)
				,zIndex: null
				,boxStyle: { 
				  background: "url('images/marqueur.png') no-repeat"
				  ,opacity: 0.85
				  ,width: "150px"
				 }
				,closeBoxMargin: "10px 2px 2px 2px"
				,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
				,infoBoxClearance: new google.maps.Size(1, 1)
				,isHidden: false
				,pane: "floatPane"
				,enableEventPropagation: false
			};

			var ib = new InfoBox(myOptions);
			ib.open(carte, listeMarqueur[i]);

			//infoWindow.open(carte,listeMarqueur[0]);
			//this.setIcon('images/marqueur.png');
			return true;
		};//);
	}
				 
	/********************** FIN **********************/
}

function setCenterToCommentUserMap(lat,lng)
{
	console.log('setCenterMap('+lat+','+lng+')');
	var latlng = new google.maps.LatLng(lat,lng);
	googleUserMap.setCenter(latlng);
}

function getUserMap()
{
	console.log('getUserMap()');
	/*var element = $("#id");
	if(element.length){
		//L'élément existe
	} else {
		//L'élément n'existe pa
	}*/

	var messages = 	[	[2,"La B.U est en rénovation jusqu'en 2016",50.609370,3.142110,'2013-09-27 14:18:25',,0,1],
						[2,"Ici c'est la salle des master 2 IAGL !",50.609772,3.136768,'2013-08-27 12:13:15',,1,1],
						[3,"KFC",50.612738,3.123405,'2013-09-10 09:55:05',,2,2],
						[4,"LEROY MERLIN, Super PROMO : pour 1000 clous achetés un marteau est offert.",50.613773,3.127281,'2013-08-27 12:13:15',,1,2]
						];
	
	var worldMapBloc = $(document.createElement('div')).attr("id","userMap").appendTo($('#bloc_page'));
	
	/* GOOGLE MAP */	
	var latlng = new google.maps.LatLng(50.60937,3.14211);
	/*HYBRID ROADMAP SATELLITE TERRAIN*/
	var options = {
		center: latlng,
		zoom: 13,
		mapTypeId: google.maps.MapTypeId.HYBRID
	};
	 
	//var 
	googleUserMap = new google.maps.Map(document.getElementById("userMap"), options);
	/* GOOGLE MAP FIN */
	
	/**************** AJOUT DE MARQUEUR ****************/
	//création de la liste de marqueurs
	var listeMarqueur = new Array();
	
	//création du marqueur
	for( var i in messages )
	{
		var marqueur = new google.maps.Marker({
			position: new google.maps.LatLng(messages[i][2],messages[i][3]),
			map: googleUserMap
		});
		marqueur.setTitle(messages[i][1]);
		if(messages[i][7]==2)
		marqueur.setIcon('images/marqueur_small.png');
		else
		marqueur.setIcon('images/marqueur_very_small.png');
		listeMarqueur.push(marqueur);
	}
	/********************* FIN ***********************/
	
	/**************** GESTION DU CLICK SUR LE MARQUEUR ****************/
	for( var i in listeMarqueur )
	{
		google.maps.event.addListener(listeMarqueur[i], 'click', function() {
			
			/** PERSONNALISATION DE LA FENETRE **/
			 var myOptions = {
				 content: "<br><p style='padding:5px;color:#000' >"+messages[i][1]+"</p><br><br><br><br><br><br><br><br><br>"
				,disableAutoPan: false
				,maxWidth: 0
				,pixelOffset: new google.maps.Size(-75, -150)
				,zIndex: null
				,boxStyle: { 
				  background: "url('images/marqueur.png') no-repeat"
				  ,opacity: 0.85
				  ,width: "150px"
				 }
				,closeBoxMargin: "10px 2px 2px 2px"
				,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
				,infoBoxClearance: new google.maps.Size(1, 1)
				,isHidden: false
				,pane: "floatPane"
				,enableEventPropagation: false
			};

			var ib = new InfoBox(myOptions);
			ib.open(googleUserMap, listeMarqueur[i]);
		});
	}		 
	/********************** FIN **********************/
}

function getUserFriendMap()
{
	console.log('getUserFriendMap()');
	/*var element = $("#id");
	if(element.length){
		//L'élément existe
	} else {
		//L'élément n'existe pa
	}*/

	var messages = 	[	[2,"La B.U est en rénovation jusqu'en 2016",50.609370,3.142110,'2013-09-27 14:18:25',,0,1],
						[2,"Ici c'est la salle des master 2 IAGL !",50.609772,3.136768,'2013-08-27 12:13:15',,1,1],
						[2,"C tro b1 la tour FL, g u tro peur lol!",48.858158,2.294660,'2013-09-10 09:55:05',,2,1],
						[2,"Amphi Bacchus!",50.609579,3.136413,'2013-08-27 12:13:15',,1,1],
						[3,"KFC",50.612738,3.123405,'2013-09-10 09:55:05',,2,2],
						[4,"LEROY MERLIN, Super PROMO : pour 1000 clous achetés un marteau est offert.",50.613773,3.127281,'2013-08-27 12:13:15',,1,2]
						];
	
	var worldMapBloc = $(document.createElement('div')).attr("id","userFriendMap").appendTo($('#bloc_page'));
	
	/* GOOGLE MAP */	
	var latlng = new google.maps.LatLng(50.60937,3.14211);
	/*HYBRID ROADMAP SATELLITE TERRAIN*/
	var options = {
		center: latlng,
		zoom: 10,
		mapTypeId: google.maps.MapTypeId.HYBRID
	};
	 
	var carte = new google.maps.Map(document.getElementById("userFriendMap"), options);
	/* GOOGLE MAP FIN */
	
	/**************** AJOUT DE MARQUEUR ****************/
	//création de la liste de marqueurs
	var listeMarqueur = new Array();
	
	//création du marqueur
	for( var i in messages )
	{
		var marqueur = new google.maps.Marker({
			position: new google.maps.LatLng(messages[i][2],messages[i][3]),
			map: carte
		});
		marqueur.setTitle(messages[i][1]);
		if(messages[i][7]==2)
		marqueur.setIcon('images/marqueur_small.png');
		else
		marqueur.setIcon('images/marqueur_very_small.png');
		listeMarqueur.push(marqueur);
	}
	/********************* FIN ***********************/
	
	/**************** GESTION DU CLICK SUR LE MARQUEUR ****************/
	for( var i in listeMarqueur )
	{
		google.maps.event.addListener(listeMarqueur[i], 'click', function() {
			
			/** PERSONNALISATION DE LA FENETRE **/
			 var myOptions = {
				 content: "<br><p style='padding:5px;color:#000' >"+messages[i][1]+"</p><br><br><br><br><br><br><br><br><br>"
				,disableAutoPan: false
				,maxWidth: 0
				,pixelOffset: new google.maps.Size(-75, -150)
				,zIndex: null
				,boxStyle: { 
				  background: "url('images/marqueur.png') no-repeat"
				  ,opacity: 0.85
				  ,width: "150px"
				 }
				,closeBoxMargin: "10px 2px 2px 2px"
				,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
				,infoBoxClearance: new google.maps.Size(1, 1)
				,isHidden: false
				,pane: "floatPane"
				,enableEventPropagation: false
			};

			var ib = new InfoBox(myOptions);
			ib.open(carte, listeMarqueur[i]);
		});
	}		 
	/********************** FIN **********************/
}

function getAccount()
{
	console.log('getAccount()');
	var account = {"pseudo":"valois","mail":"valois.vander@gmail.com","password":"******"};
	
	var accountBloc = $(document.createElement('div')).attr('id','myAccount').appendTo($('#bloc_page'));
	var form = $(document.createElement('form')).attr('name','accountForm').attr('id','accountForm').appendTo(accountBloc);
	
	$(document.createElement('br')).appendTo(form);
	
	$(document.createElement('inline')).html('Pseudo :').appendTo(form);
	$(document.createElement('input')).attr('type','text').attr('name','pseudo').attr('value',account.pseudo).attr('id','textForm').appendTo(form);
	$(document.createElement('input')).attr('type','button').attr('value','Save').attr('onClick','rien').attr('id','buttonForm').appendTo(form);
	//onClick=' document.forms["changer"].elements["zonetexte"].value = "NOUVEAU" '
	
	$(document.createElement('br')).appendTo(form);
	
	$(document.createElement('inline')).html('Mail :').appendTo(form);
	$(document.createElement('input')).attr('type','text').attr('name','mail1').attr('value',account.mail).attr('id','textForm').appendTo(form);
	$(document.createElement('inline')).html('Confirm :').appendTo(form);
	$(document.createElement('input')).attr('type','text').attr('name','mail2').attr('value',account.mail).attr('id','textForm').appendTo(form);
	$(document.createElement('input')).attr('type','button').attr('value','Save').attr('onClick','rien').attr('id','buttonForm').appendTo(form);
	
	$(document.createElement('br')).appendTo(form);
	
	$(document.createElement('inline')).html('Pass :').appendTo(form);
	$(document.createElement('input')).attr('type','password').attr('name','pass1').attr('value',account.password).attr('id','textForm').appendTo(form);
	$(document.createElement('inline')).html('Confirm :').appendTo(form);
	$(document.createElement('input')).attr('type','password').attr('name','pass2').attr('value',account.password).attr('id','textForm').appendTo(form);
	$(document.createElement('input')).attr('type','button').attr('value','Save').attr('onClick','rien').attr('id','buttonForm').appendTo(form);
	
	$(document.createElement('br')).appendTo(form);
	
	$(document.createElement('input')).attr('type','button').attr('value','Save All').attr('onClick','WSCreateAccount(accountForm.pseudo.value,accountForm.pass1.value,accountForm.mail1.value)').attr('id','buttonForm').appendTo(form);
}

function getNews()
{
	console.log('getNews()');
	var newsBloc = $(document.createElement('div')).attr("id","news").appendTo($('#bloc_page'));
}

function Datagrid (name, dataArray, headerArray)
{
	this.id = globalDatagrid.length + 1;
	this.name = name;
	this.header = headerArray;
	this.datas = dataArray;
	this.element = null;
	
	this.rowPerPage = 10;
	this.currentPage = 1;
	this.totalRows = this.datas.length;
	this.maxPage = parseInt(this.totalRows/this.rowPerPage);
	if(this.maxPage != this.totalRows/this.rowPerPage ) this.maxPage+=1;
}

Datagrid.prototype.reBuildTable	= function (page)
{
	console.log('reBuildTable() p:'+page);
	this.currentPage=page;
	page-=1;
	
	var tab = "<table>";
	tab += getHeaderRow(this.header);
	tab += getRows(this.datas.slice(page*this.rowPerPage,(page*this.rowPerPage)+this.rowPerPage));
	tab += "</table>";
	
	$( "#"+this.name ).replaceWith($(document.createElement('div')).attr("id",this.name).append(tab));

	this.buildPager();
}

Datagrid.prototype.buildTable	= function ()
{
	console.log('buildTable()');
	
	var tab = "<table>";
	tab += getHeaderRow(this.header);
	tab += getRows(this.datas.slice(0,this.rowPerPage));
	tab += "</table>";
	
	this.element = $(document.createElement('div')).attr("id",this.name).appendTo($('#bloc_page')).append(tab);	
}

Datagrid.prototype.buildPager	= function ()
{	
	console.log('buildPager() p:'+this.currentPage);
	thisObject = this;
	var table = $(document.createElement('table')).attr("id","pager_"+this.name).attr("style","text-align: center;");
	var tr = $(document.createElement('tr')).appendTo(table);

	if(this.currentPage-2 > 0)
	{	$(document.createElement('td')).attr("id",this.name+"First").attr("onclick","clickPager("+this.id+","+1+")").html("First").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Prev").attr("onclick","clickPager("+this.id+","+(this.currentPage-1)+")").html("Prev").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage-2)).attr("onclick","clickPager("+this.id+","+(this.currentPage-2)+")").html(this.currentPage-2).appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage-1)).attr("onclick","clickPager("+this.id+","+(this.currentPage-1)+")").html(this.currentPage-1).appendTo(tr);
	}else if(this.currentPage-1 > 0)
	{	$(document.createElement('td')).attr("id",this.name+"First").attr("onclick","clickPager("+this.id+","+1+")").html("First").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Prev").attr("onclick","clickPager("+this.id+","+(this.currentPage-1)+")").html("Prev").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage-1)).attr("onclick","clickPager("+this.id+","+(this.currentPage-1)+")").html(this.currentPage-1).appendTo(tr);
	}
	
	$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage)).attr("onclick","clickPager("+this.id+","+(this.currentPage)+")").attr("style","border:2px solid #ddd;").html(this.currentPage).appendTo(tr);
		
	if(this.currentPage+2 < this.maxPage+1)
	{	$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage+1)).attr("onclick","clickPager("+this.id+","+(this.currentPage+1)+")").html(this.currentPage+1).appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage+2)).attr("onclick","clickPager("+this.id+","+(this.currentPage+2)+")").html(this.currentPage+2).appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Next").attr("onclick","clickPager("+this.id+","+(this.currentPage+1)+")").html("Next").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Last").attr("onclick","clickPager("+this.id+","+(this.maxPage)+")").html("Last").appendTo(tr);
	}else if(this.currentPage+1 < this.maxPage+1)
	{	$(document.createElement('td')).attr("id",this.name+"page"+(this.currentPage+1)).attr("onclick","clickPager("+this.id+","+(this.currentPage+1)+")").html(this.currentPage+1).appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Next").attr("onclick","clickPager("+this.id+","+(this.currentPage+1)+")").html("Next").appendTo(tr);
		$(document.createElement('td')).attr("id",this.name+"Last").attr("onclick","clickPager("+this.id+","+(this.maxPage)+")").html("Last").appendTo(tr);
	}
	
	$( "#"+this.name ).append(table);
}

function clickPager(id,page)
{
	console.log('clickPager('+id+','+page+')');
	globalDatagrid[id-1].reBuildTable(page);
}

function getHeaderRow(paramNames)
{
	var row = "<tr>";
	for(var i in paramNames)
	{
		row += "<th>"+paramNames[i]+"</th>";
	}
	row += "</tr>";
	return row;
}

function getRows(parameters)
{
	var rows = "";
	for(var i in parameters)
	{
		rows += "<tr>";
		for(var j in parameters[i])
		{
			rows += "<td>"+parameters[i][j]+"</td>";
		}
		rows += "</tr>";
	}
	return rows;
}

/*function loadPage(url){
	document.getElementById('if').contentWindow.document.location.href=url;
}*/